# Jack Chua
# MPI All Reduce

# "=============================================="
# "           all: build mpi-allr                "
# "         clean: remove generated files        "
# "           run: submit mpi-run.pbs to queue   "
# "          dist: create tgz turn-in            "
# "=============================================="	

PROJID = HW5_JackChua
LINK_OPENMP_GCC = -fopenmp

MPCC	= mpicc
OPT		= -g -O -Wall -Wextra $(LINK_OPENMP_GCC)
LIBS	= -lm
CFLAGS  = -O 

.c.o:
	$(MPCC) $(OPT) -o $@ $< -c

all: mpi-allr

mpi-allr: mpi-allr-driver.o mpi-allr.o
	$(MPCC) $(OPT) -o $@ $^ $(LIBS)

run : mpi-allr
	qsub mpi-run.pbs

DISTFILES = makefile
DISTFILES += mpi-allr.c
DISTFILES += mpi-allr-driver.c
DISTFILES += mpi-allr.h
DISTFILES += mpi-run.pbs
DISTFILES += Data/max.output
DISTFILES += Data/min.output
DISTFILES += Data/sum.output

.PHONY : clean
.PHONY : dist

clean :
	rm -f *.o
	rm mpi-allr

dist : 
	if test -d "$(PROJID)" ; then rm -rf $(PROJID)/ ; fi
	mkdir -p $(PROJID)
	cp -r $(DISTFILES) $(PROJID)
	tar -cvf $(PROJID).tgz $(PROJID)/
	rm -rf $(PROJID)
	
